package cc.koit.hulk.service.impl;

import cc.koit.hulk.dao.entity.User;
import cc.koit.hulk.dao.mapper.UserMapper;
import cc.koit.hulk.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private UserMapper userMapper;

    @Override
    @CacheEvict(value="koit_cache", key="'user_list'")
    public void create(User user) {
        userMapper.insert(user);
        logger.info("插入成功，返回id："+user.getId());
    }


    @Override
    @Cacheable(value="koit_cache", key="'user_list'")
    public List<User> listAll() {
        return userMapper.selects();
    }
}
